Skip to content

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Sep 4, 2025

Added functionality to handle file drops on the trash icon in the task manager

  1. Implemented moveFilesToTrash method that converts URL paths to local files and moves them to system trash
  2. Added file drop detection for "dde-trash" item ID with proper debug logging
  3. Included necessary Qt headers for file operations (QFile, QFileInfo, QProcess, QUrl)
  4. Added error handling for empty file paths with warning messages

feat: 添加回收站文件拖放支持

在任务管理器中添加了对回收站图标的文件拖放处理功能

  1. 实现了moveFilesToTrash方法,将URL路径转换为本地文件并移动到系统回收站
  2. 添加了对"dde-trash"项目ID的文件拖放检测,包含适当的调试日志
  3. 包含了文件操作所需的Qt头文件(QFile、QFileInfo、QProcess、QUrl)
  4. 为空的文件路径添加了错误处理,包含警告消息

Pms: BUG-271091

Summary by Sourcery

Add drag-and-drop handling for files on the trash icon by implementing moveFilesToTrash, incorporating debug logging and error handling.

New Features:

  • Add support for dropping files onto the trash icon in the task manager
  • Implement moveFilesToTrash to convert URL paths and move files to the system trash
  • Log debug messages for file drop actions and warnings for empty file paths
  • Include necessary Qt headers (QFile, QUrl) for file operations

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 4, 2025

Reviewer's Guide

This PR adds drag-and-drop support to the trash icon in the task manager by detecting drops on the "dde-trash" item, moving dropped files to the system trash via a new moveFilesToTrash method, and including necessary Qt headers along with error and debug logging.

File-Level Changes

Change Details Files
Extend dropFilesOnItem to handle trash drops
  • Detect "dde-trash" itemId and early return path
  • Add debug logging for dropped URLs
  • Invoke moveFilesToTrash when trash icon receives drops
panels/dock/taskmanager/taskmanager.cpp
Add moveFilesToTrash method for sending files to system trash
  • Declare private moveFilesToTrash API in header
  • Iterate over dropped URLs and convert to local file paths
  • Call QFile::moveToTrash and log success or empty-path warnings
panels/dock/taskmanager/taskmanager.cpp
panels/dock/taskmanager/taskmanager.h
Include Qt file and URL headers
  • Add #include
  • Add #include
panels/dock/taskmanager/taskmanager.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@wjyrich wjyrich force-pushed the fix-bug-271091 branch 2 times, most recently from c4176c0 to 10359c8 Compare September 4, 2025 09:13
Added functionality to handle file drops on the trash icon in the task
manager
1. Implemented moveFilesToTrash method that converts URL paths to local
files and moves them to system trash
2. Added file drop detection for "dde-trash" item ID with proper debug
logging
3. Included necessary Qt headers for file operations (QFile, QFileInfo,
QProcess, QUrl)
4. Added error handling for empty file paths with warning messages

feat: 添加回收站文件拖放支持

在任务管理器中添加了对回收站图标的文件拖放处理功能
1. 实现了moveFilesToTrash方法,将URL路径转换为本地文件并移动到系统回收站
2. 添加了对"dde-trash"项目ID的文件拖放检测,包含适当的调试日志
3. 包含了文件操作所需的Qt头文件(QFile、QFileInfo、QProcess、QUrl)
4. 为空的文件路径添加了错误处理,包含警告消息

Pms: BUG-271091
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查报告

总体评价

这段代码为任务管理器添加了将文件拖放到回收站的功能,整体实现较为清晰,但有一些可以改进的地方。

具体分析

1. 语法逻辑

  • 语法正确,逻辑清晰
  • 新增的 moveFilesToTrash 方法职责单一,专注于将文件移动到回收站
  • dropFilesOnItem 中对回收站特殊情况的判断处理得当

2. 代码质量

  • 优点:
    • 使用了日志记录,便于调试和问题追踪
    • 代码结构清晰,方法职责单一
  • 改进建议:
    • moveFilesToTrash 方法缺少参数有效性检查
    • 没有对文件路径进行空值或有效性验证
    • 错误处理可以更加完善,例如当 moveToTrash 失败时可以提供用户反馈

3. 代码性能

  • 当前实现对于每个文件都会调用一次 moveToTrash,可以考虑批量处理
  • 对于大量文件的情况,可以考虑添加进度反馈

4. 代码安全

  • 需要验证文件路径的有效性和安全性,防止路径遍历攻击
  • 应该检查文件是否存在且有操作权限
  • 没有对 URL 格式进行验证,可能导致安全问题

改进建议

  1. moveFilesToTrash 方法开始处添加参数验证:
void TaskManager::moveFilesToTrash(const QStringList& urls)
{
    if (urls.isEmpty()) {
        qCWarning(taskManagerLog) << "Empty URLs list provided";
        return;
    }
    
    // 将文件路径转换为本地路径并移动到回收站
    for (const QString& urlString : urls) {
        if (urlString.isEmpty()) {
            qCWarning(taskManagerLog) << "Empty URL encountered";
            continue;
        }
        
        QUrl url(urlString);
        if (!url.isValid()) {
            qCWarning(taskManagerLog) << "Invalid URL format:" << urlString;
            continue;
        }
        
        QString filePath = url.toLocalFile();
        if (filePath.isEmpty()) {
            qCWarning(taskManagerLog) << "Failed to convert URL to local file:" << urlString;
            continue;
        }
        
        // 添加文件存在性检查
        QFileInfo fileInfo(filePath);
        if (!fileInfo.exists()) {
            qCWarning(taskManagerLog) << "File does not exist:" << filePath;
            continue;
        }
        
        if (!fileInfo.isReadable()) {
            qCWarning(taskManagerLog) << "No read permission for file:" << filePath;
            continue;
        }
        
        if (DTrashManager::instance()->moveToTrash(filePath)) {
            qCDebug(taskManagerLog) << "Successfully moved to trash:" << filePath;
        } else {
            qCWarning(taskManagerLog) << "Failed to move to trash:" << filePath;
            // 可以考虑在这里添加用户反馈
        }
    }
}
  1. 考虑添加批量处理和进度反馈:
void TaskManager::moveFilesToTrash(const QStringList& urls)
{
    // ... 参数验证代码 ...
    
    int successCount = 0;
    int totalCount = urls.size();
    
    for (const QString& urlString : urls) {
        // ... 验证代码 ...
        
        if (DTrashManager::instance()->moveToTrash(filePath)) {
            successCount++;
            qCDebug(taskManagerLog) << "Successfully moved to trash:" << filePath;
        } else {
            qCWarning(taskManagerLog) << "Failed to move to trash:" << filePath;
        }
    }
    
    // 可以在这里发送信号通知操作完成和成功率
    emit trashOperationCompleted(successCount, totalCount);
}
  1. 在头文件中添加新的信号声明:
Q_SIGNALS:
    void dataModelChanged();
    void windowSplitChanged();
    void trashOperationCompleted(int successCount, int totalCount);
  1. 考虑添加用户反馈机制,例如当操作失败时显示通知。

这些建议可以提高代码的健壮性、安全性和用户体验,同时保持代码的清晰和可维护性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, wjyrich

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@18202781743 18202781743 merged commit 83021e8 into linuxdeepin:master Sep 4, 2025
9 of 10 checks passed
wjyrich added a commit to wjyrich/dde-shell that referenced this pull request Oct 24, 2025
文管采用了相关脚本处理,无需dde-shell特殊处理回收站,只需保持原有逻辑。

Logs:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants